package service

import (
	"context"

	"gitee.com/flycash/simple-im/internal/domain"
	"gitee.com/flycash/simple-im/internal/repository"
)

type ChannelService interface {
	LastMessageID(ctx context.Context, uid, channelID int64) (int64, error)
	UpdateLastMessageID(ctx context.Context, uid int64, record domain.ChannelMsgReadRecord) error
}

type channelService struct {
	repo repository.ChannelMemberReadRecordRepo
}

func NewChannelService(repo repository.ChannelMemberReadRecordRepo) ChannelService {
	return &channelService{
		repo: repo,
	}
}

func (c *channelService) LastMessageID(ctx context.Context, uid, channelID int64) (int64, error) {
	return c.repo.GetLastReadMsgID(ctx, uid, channelID)
}

func (c *channelService) UpdateLastMessageID(ctx context.Context, uid int64, record domain.ChannelMsgReadRecord) error {
	return c.repo.Save(ctx, uid, record)
}
